package org.catdroid.apps;

import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.Log;

public class CancelDownload extends Activity {
	private static final String TAG = "CancelDownload";
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		//De moment, farem que canceli la descarrega amb nomes clickarhi, potser mes endavant interessa confirmar?
		Log.i(TAG, "onCreate");
		Bundle extras = getIntent().getExtras();
		if(extras != null) {
			String url = extras.getString("org.catdroid.apps.url");
			if(url != null) {
				Log.i(TAG, "Cancelando: " + url);
				setCancelled(url);
			} else Log.i(TAG, "Url null");
		} else Log.i(TAG, "Extras null");
		finish();
		super.onCreate(savedInstanceState);
	}
	
	private void setCancelled(String url) {
		Log.i(TAG, "setCancelled: " + url);
		SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
		SharedPreferences.Editor editor = settings.edit();
		editor.putBoolean(url, true);
		editor.commit();
	}

}
